#include<bits/stdc++.h>
using namespace std;
char ch1,ch2;
char way[5]={0};
int nx,ny;
char x,y;
int main()
{
    while(~scanf("int %c,%c;",&x,&y))
    {
    	char ch;
    	int num;
    	getchar();
        for(int i=0;i<2;i++)
        {
     	   scanf("fu %c %d;",&ch,&num);
     	   ch==x?nx=num:ny=num;
   	       getchar();
    	}
        while(1)
        {
            scanf("%s",way);
            if(way[0]=='E')
            {
            	getchar();
                printf("%d %d\n",nx,ny);
                break;          
            }
            else
            {
                scanf(" %c %c;",&ch1,&ch2);
                if(way[0]=='A')    
                {
                    x==ch1?nx=nx+ny:ny=ny+nx;
                }
                if(way[0]=='S')
                {
                    x==ch1?nx=nx-ny:ny=ny-nx;
                }
                if(way[0]=='M')
                {
                    x==ch1?nx=nx*ny:ny=ny*nx;
                }
                if(way[0]=='D')
                {
                    x==ch1?nx=nx/ny:ny=ny/nx;
                }
            }
        }
    }
}